package com.hundsun.yr.universal.p2p.bean;

import android.text.TextUtils;

import com.hundsun.yr.universal.library.utils.HsDateUtils;
import com.hundsun.yr.universal.library.utils.HsNumberUtils;
import com.hundsun.yr.universal.library.utils.MathUtils;



/**
 * @Title: Discounts.java 
 * @Description: 优惠抵扣
 * @date 2016-3-4 下午2:41:53 
 * @author:hejun.shen
 * @email:shenhj15971@hundsun.com 
 * @replace author:
 * @replace date:
 * @version V1.0   
 */
public class Discounts {

	/**可用价值**/
	private String canUseNum;
	/**抵扣比例**/
	private String deductionRatio;
	/**抵扣规则 ALLDDCB("1","全额抵扣"),PRPSL("2","按投资金额的百分比");**/
	private String deductionRule;
	/**优惠编号**/
	private String discountId;
	/**优惠子类型(单个、累计) SINGLE("1", "单个"), CVML("2", "累积");**/
	private String discountSubType;
	/**优惠类型(红包、现金券。。) REDPACKET("1", "红包"), INTEGRAL("2", "积分"),  CASH("3", "现金劵"), OTHER("4", "其他");**/
	private String discountType;
	/**优惠派发价值**/
	private String distributeNum;
	/**失效日期**/
	private String endValidDate;
	/**冻结价值**/
	private String frozenNum;
	/**优惠拥有价值**/
	private String holdNum;
	/**可用最小投资金额**/
	private String minInvestAmnt;
	/**生效日期**/
	private String startValidDate;
	/**生效状态VALID("0", "正常"),  INVALID("1", "失效"),  USED("2", "已使用"),  FROZEN("3", "冻结")**/
	private String status;
	/**优惠使用价值**/
	private String usedNum;
	/**用户编号**/
	private String userId;
	
	
	
	
	public String getCanUseNum() {
		return canUseNum;
	}
	public void setCanUseNum(String canUseNum) {
		this.canUseNum = canUseNum;
	}
	public String getDeductionRatio() {
		return deductionRatio;
	}
	public void setDeductionRatio(String deductionRatio) {
		this.deductionRatio = deductionRatio;
	}
	public String getDeductionRule() {
		return deductionRule;
	}
	public void setDeductionRule(String deductionRule) {
		this.deductionRule = deductionRule;
	}
	public String getDiscountId() {
		return discountId;
	}
	public void setDiscountId(String discountId) {
		this.discountId = discountId;
	}
	public String getDiscountSubType() {
		return discountSubType;
	}
	public void setDiscountSubType(String discountSubType) {
		this.discountSubType = discountSubType;
	}
	public String getDiscountType() {
		return discountType;
	}
	public void setDiscountType(String discountType) {
		this.discountType = discountType;
	}
	public String getDistributeNum() {
		return distributeNum;
	}
	public void setDistributeNum(String distributeNum) {
		this.distributeNum = distributeNum;
	}
	public String getEndValidDate() {
		return endValidDate;
	}
	public void setEndValidDate(String endValidDate) {
		this.endValidDate = endValidDate;
	}
	public String getFrozenNum() {
		return frozenNum;
	}
	public void setFrozenNum(String frozenNum) {
		this.frozenNum = frozenNum;
	}
	public String getHoldNum() {
		return holdNum;
	}
	public void setHoldNum(String holdNum) {
		this.holdNum = holdNum;
	}
	public String getMinInvestAmnt() {
		return minInvestAmnt;
	}
	public void setMinInvestAmnt(String minInvestAmnt) {
		this.minInvestAmnt = minInvestAmnt;
	}
	public String getStartValidDate() {
		return startValidDate;
	}
	public void setStartValidDate(String startValidDate) {
		this.startValidDate = startValidDate;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getUsedNum() {
		return usedNum;
	}
	public void setUsedNum(String usedNum) {
		this.usedNum = usedNum;
	}
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	
	/**
	 * 显示红包金额
	 * @return
	 */
	public String displayAmnt(){
		
		return HsNumberUtils.moneyFormat(minInvestAmnt);
	}
	/**
	 * 可用日期
	 * @return
	 */
	public String getValidDate() {
		String validDate=HsDateUtils.timeformat(HsDateUtils.farmat_date_3, endValidDate);
		return validDate;
	}
	
	
	/**
	 * 最大优惠金额
	 * @return
	 */
	public String maxDiscounts(String investAmnt){
		String maxMoney="0";
		if(TextUtils.equals(deductionRule, "ALLDDCB")){
			maxMoney=canUseNum;
		}else if(TextUtils.equals(deductionRule, "PRPSL")){
			String deduction=HsNumberUtils.rounding2Digits(MathUtils.multiply(MathUtils.division(deductionRatio, "100"),investAmnt));
			if(MathUtils.compare(deduction, canUseNum)<0){
				maxMoney=deduction;
			}else{
				maxMoney=canUseNum;
			}
		}
		return maxMoney;
	}
	
	/**
	 * 优惠金额
	 * @param investAmont 投资金额
	 * @return String
	 */
	public String discountMoney(String investAmnt){
		
		String discount="0";
		if(MathUtils.compare(investAmnt, maxDiscounts(investAmnt))<0){
			discount=investAmnt;
		}else{
			discount=maxDiscounts(investAmnt);
		}
		return HsNumberUtils.moneyThousandsFormat(discount);
	}
	
	/**
	 * 显示支付金额
	 * @param investAmont
	 * @return
	 */
	public String payMoney(String investAmnt){
		
		String pay="0";
		if(MathUtils.compare(investAmnt, maxDiscounts(investAmnt))<0){
			pay="0";
		}else{
			pay=MathUtils.subtract(investAmnt,maxDiscounts(investAmnt));
		}
		return HsNumberUtils.moneyThousandsFormat(pay);
	}
	
}
